import { Service } from "~/core/service";
import { NetService } from "~/util/net.service";
import { Inject, Debounce } from "~/core/decorator";
import { serviceProduct } from "~/config/server";

export class ProductService extends Service {

  @Inject(NetService)
  private netService: NetService;

  /**
    * 查询所有未删除的产品
    */
  findAllPublicProductList() {
    return this.netService.send({
      server: serviceProduct.productController.findAllPublicProductList
    })
  }

  /**
    * 查询所有未删除的产品
    */
  addProduct(data) {
    return this.netService.send({
      server: serviceProduct.productController.addProduct,
      data: {
        productName: data.productName,
        productContent: data.productContent,
        productPrice: data.productPrice,
        remark: data.remark
      }
    })
  }

  /**
   * 编辑产品
   */
  updateProduct(data) {
    return this.netService.send({
      server: serviceProduct.productController.updateProduct,
      data: {
        id: data.id,
        productName: data.productName,
        productContent: data.productContent,
        productPrice: data.productPrice,
        remark: data.remark
      }
    })
  }

  /**
   * 删除产品
   */
  deleteProduct(id: string) {
    return this.netService.send({
      server: serviceProduct.productController.deleteProduct,
      append: id
    })
  }

  /**
   * 发布产品
   */
  publicProduct(id: string) {
    return this.netService.send({
      server: serviceProduct.productController.publicProduct,
      data: {id}
    })
  }
  
  /**
   * 分页查询所有的产品
   */
  findListByPage(data, page) {
    return this.netService.send({
      server: serviceProduct.productController.findListByPage,
      data,
      page
    })
  }

}